package cn.lei.uicontrols;

import android.app.AlertDialog;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.CheckBox;

public class AtyUsingCheckBox extends AppCompatActivity {

    private CheckBox cb1, cb2, cb3, cb4;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_aty_using_check_box);

        cb1 = (CheckBox) findViewById(R.id.cb1);
        cb2 = (CheckBox) findViewById(R.id.cb2);
        cb3 = (CheckBox) findViewById(R.id.cb3);
        cb4 = (CheckBox) findViewById(R.id.cb4);

        findViewById(R.id.btnSubmit).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String str = "中午要吃什么：\n";
                if (cb1.isChecked()) {
                    str += "方便面\n";
                }
                if (cb2.isChecked()) {
                    str += "肉饼\n";
                }
                if (cb3.isChecked()) {
                    str += "面条\n";
                }
                if (cb4.isChecked()) {
                    str += "盖饭\n";
                }

                new AlertDialog.Builder(AtyUsingCheckBox.this).setTitle("结果").setMessage(str).setPositiveButton("关闭", null).show();
            }
        });
    }
}
